py交易

0x1 题目

Python 2.7

py.pyc

0x2 解题步骤

0x1 反编译py.pyc

uncompyle6 Py.pyc > py.py

得到py.py文件:

# uncompyle6 version 3.2.3
# Python bytecode 2.7 (62211)
# Decompiled from: Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)]
# Embedded file name: 1.py
# Compiled at: 2017-06-03 10:20:43
import base64

def encode(message):
    s = ''
    for i in message:
        x = ord(i) ^ 32
        x = x + 16
        s += chr(x)

    return base64.b64encode(s)


correct = 'XlNkVmtUI1MgXWBZXCFeKY+AaXNt'
flag = ''
print 'Input flag:'
flag = raw_input()
if encode(flag) == correct:
    print 'correct'
else:
    print 'wrong'
# okay decompiling Py.pyc

0x2 编写逆算法

def decode(message):
    message = base64.b64decode(message)
    print "message:" + message
    s = ''
    for i in message:
        tmp = ord(i)
        print "tmp:",
        tmp = tmp -16
        print tmp
        s += chr(tmp^32)
    return s


print decode(correct)

得到flag: nctf{d3c0mpil1n9_PyC}